#include <log.h>
#include <stdarg.h>

void log_begin(unsigned char log_level, char *mod) {
    char *prompt;
    switch (log_level) {
    case LEVEL_ERROR:
        prompt = "\033[31mE";
        break;
    case LEVEL_WARNING:
        prompt = "\033[33mW";
        break;

    case LEVEL_INFO:
        prompt = "\033[37mI";
        break;

    case LEVEL_DEBUG:
        prompt = "\033[35mD";
        break;

    default:
        prompt = "\033[37mI";
        break;
    }
    printf("%s> %s> ", prompt, mod);
}

void log_end() { printf("\033[0m\n"); }

void log(unsigned char log_level, unsigned char default_level, char *mod,
         char *fmt, ...) {
    static char ulog_buf[86];
    if (log_level <= default_level) {
        log_begin(log_level, mod);
        va_list args;
        va_start(args, fmt);
        vsprintf(ulog_buf, fmt, args);
        va_end(args);
        printf("%s", ulog_buf);
        log_end();
    }
}